home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / internet / inter / wmap.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-03-07  |  5.1 KB  |  153 lines

  1. VERSION 2.00
  2. Begin Form frmWeather 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Weather Map Gopher"
  5.    ClientHeight    =   2730
  6.    ClientLeft      =   3615
  7.    ClientTop       =   2850
  8.    ClientWidth     =   5190
  9.    Height          =   3135
  10.    Icon            =   WMAP.FRX:0000
  11.    Left            =   3555
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   2730
  15.    ScaleWidth      =   5190
  16.    Top             =   2505
  17.    Visible         =   0   'False
  18.    Width           =   5310
  19.    WindowState     =   1  'Minimized
  20.    Begin Timer Timer1 
  21.       Interval        =   50000
  22.       Left            =   180
  23.       Top             =   720
  24.    End
  25.    Begin dsSocket dsSocket1 
  26.       DataSize        =   2048
  27.       Left            =   180
  28.       Linger          =   0   'False
  29.       LocalPort       =   0
  30.       RemoteDotAddr   =   ""
  31.       RemoteHost      =   ""
  32.       RemotePort      =   0
  33.       ServiceName     =   ""
  34.       Timeout         =   0
  35.       Top             =   180
  36.    End
  37. DefInt A-Z
  38. Declare Function SystemParametersInfo Lib "User" (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer
  39. Declare Function GIFToBMP Lib "giftobmp.dll" (ByVal lpstrGIF As String, ByVal lpstrBMP As String) As Integer
  40. Dim Connected, DoneIt, EastFlag, StartMinuite
  41. Sub dsSocket1_Connect ()
  42.     '-- Set the connected flag
  43.     Connected = True
  44. End Sub
  45. Sub dsSocket1_Exception (ErrorCode As Integer, ErrorDesc As String)
  46.     If ErrorCode = DSSOCK_DISCONNECTED Then
  47.         '-- We've disconnected
  48.         Connected = False
  49.     End If
  50. End Sub
  51. Sub dsSocket1_Receive (ReceiveData As String)
  52. '-- This routine occurs when we're receiving a file.
  53.     '-- If this is the beginning of the GIF file, then
  54.     '   the block starts with the letters "GIF"
  55.     If Left$(ReceiveData, 3) = "GIF" Then
  56.         '-- Open the GIF File
  57.         SrcFile$ = App.Path & "\WMAP.GIF"
  58.         Open SrcFile$ For Output As 1
  59.         Close 1
  60.         Open SrcFile$ For Binary As 1
  61.     End If
  62.     '-- Write the data
  63.     Put #1, , ReceiveData
  64.     '-- Is the transfer complete?
  65.     If Asc(Right$(ReceiveData, 1)) = 59 Then
  66.         '-- Yes. Close the file
  67.         Close 1
  68.         
  69.         '-- Convert the GIF file to a BMP file using
  70.         '   Dolphin Systems' simple GIF2BMP converter
  71.         DestFile$ = App.Path & "\WMAP.BMP"
  72.         SrcFile$ = App.Path & "\WMAP.GIF"
  73.         ErrCode = GIFToBMP(SrcFile$, DestFile$)
  74.         
  75.         '-- If there were no problems, change the
  76.         '   Windows wallpaper to the new bitmap
  77.         If ErrCode = 0 Then
  78.             Dummy = SystemParametersInfo(20, 0, DestFile$, 1)
  79.             '-- Tell everyone that we've done it for this hour.
  80.             DoneIt = True
  81.         End If
  82.         '-- Close the connection
  83.         dsSocket1.Action = DSSOCK_CLOSE
  84.         
  85.         '-- Wait until we're not connected
  86.         Do
  87.             DoEvents
  88.         Loop Until Not Connected
  89.         
  90.         '-- Re-enable the timer
  91.         Timer1.Enabled = True
  92.     End If
  93. End Sub
  94. Sub Form_Load ()
  95.     '-- /E on the command line tells WMAP to
  96.     '   retrieve the eastern US photo instead of
  97.     '   the western US
  98.     C$ = Trim$(UCase$(Command$))
  99.     EastFlag = InStr(C$, "/E")
  100.     '-- Record the minutes past the hour right now
  101.     StartMinuite = Minute(Now)
  102.     '-- Use a large buffer size
  103.     dsSocket1.DataSize = 30000
  104.     '-- Go get the latest photo now.
  105.     GetPicture
  106. End Sub
  107. Sub Form_Unload (Cancel As Integer)
  108.     '-- Disconnect (even if we're not connected)
  109.     On Error Resume Next
  110.     dsSocket1.Action = DSSOCK_CLOSE
  111.     End
  112. End Sub
  113. Sub GetPicture ()
  114. '-- This routine connects to the gopher weather server and sends the
  115. '   command to retrieve the latest weather map .GIF file
  116.     '-- Temporarily disable the timer
  117.     Timer1.Enabled = False
  118.     '-- Set the port and address
  119.     dsSocket1.RemotePort = 70
  120.     dsSocket1.RemoteHost = "wx.atmos.uiuc.edu"
  121.     '-- Catch any errors that result from trying to connect
  122.     On Error Resume Next
  123.     dsSocket1.Action = DSSOCK_CONNECT
  124.     If Err Then
  125.         '-- An error occurred. Try again at the next timer
  126.         Timer1.Enabled = True
  127.         Exit Sub
  128.     End If
  129.     '-- No errors. Wait until we've connected
  130.     Do
  131.         DoEvents
  132.     Loop Until Connected
  133.     '-- Send the command to retrieve either the eastern or western US weather map.
  134.     If EastFlag Then
  135.         dsSocket1.Send = "9/Images/Satellite Images/Satellite East IR/00LATEST.GIF" & Chr$(13) & Chr$(10)
  136.     Else
  137.         dsSocket1.Send = "9/Images/Satellite Images/Satellite West IR/00LATEST.GIF" & Chr$(13) & Chr$(10)
  138.     End If
  139. End Sub
  140. Sub Timer1_Timer ()
  141.     '-- Has one hour passed?
  142.     If Minute(Now) = StartMinuite Then
  143.         '-- Yes. Have we already done this hour?
  144.         If Not DoneIt Then
  145.             '-- Nope. Go to it.
  146.             GetPicture
  147.         End If
  148.     Else
  149.         '-- No.
  150.         DoneIt = False
  151.     End If
  152. End Sub
  153.